package com.fadadianqi.goods.dao.ibatis;

import com.fadadianqi.commons.GenericDAOSuport;
import com.fadadianqi.goods.dao.CategoryDAO;
import com.fadadianqi.goods.model.Category;
import com.yeqiangwei.commons.util.Pagination;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author aroot
 */
@Component
public class CategoryDAOImpl extends GenericDAOSuport<String, Category> implements
        CategoryDAO {

    @Override
    protected Class<?> getObjectClass() {
        return Category.class;
    }

    @Override
    protected String getTableName() {
        return "category";
    }

    @Override
    public List<Category> findAll() {
        Pagination pagination = new Pagination(1, 3000);
        pagination.setOrderList(new Pagination.Order[]{
                Pagination.getNewOrder("first_letter", Boolean.TRUE)
        });
        return super.findAll(pagination);
    }

    @Override
    public Category getByName(String name) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(Category.PROP_NAME, name);
        return super.getByPropertys(map);
    }

    @Override
    public List<Category> findByFirstLetter(String flt, Pagination pagination) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("pagination", pagination);
        map.put("firstLetter", flt);
        return super.findByPropertys(map);
    }

    @Override
    public int countByFirstLetter(String flt) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("firstLetter", flt);
        return super.countAll(map);
    }

}
